package cn.hwadee.muying.service;

import cn.hwadee.muying.entity.Job;
import cn.hwadee.muying.entity.WorkerLevel;
import cn.hwadee.muying.mapper.WorkerLevelMapper;
import cn.hwadee.muying.commons.base.BaseService;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import org.springframework.stereotype.Service;
import cn.hwadee.muying.entity.User;
import cn.hwadee.muying.commons.page.MyPage;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;

/**
 * <p>
 * 员工等级 服务实现类
 * </p>
 *
 * @author Carlos
 * @since 2018-08-07
 */
@Service
public class WorkerLevelService extends BaseService<WorkerLevelMapper, WorkerLevel> {

    @Autowired
    private WorkerLevelMapper workerLevelMapper;
    @Autowired
    private JobService jobService;

    public MyPage<WorkerLevel> list(MyPage<WorkerLevel> page, User cUser,String keyword) throws Exception{
        List<WorkerLevel> workerLevels = workerLevelMapper.list(page,cUser,keyword);
        for(WorkerLevel workerLevel:workerLevels){
            Job job=jobService.selectById(workerLevel.getJobId());
            workerLevel.setJobName(job.getName());
            if(workerLevel.getHasNext()){
                WorkerLevel temp=workerLevelMapper.selectById(workerLevel.getNextId());
                workerLevel.setNextLevelName(temp.getName());
            }
        }
        page.setRecords(workerLevels);
        return page;
    }

    public List<WorkerLevel> selectAll() {
        return workerLevelMapper.selectList(
                new EntityWrapper<WorkerLevel>()
                .and("valid=1")
        );
    }
}
